<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

use App\Models\Address;

class OrderAddress extends Model
{
    protected $table = "c_order_addresses";

    public function province()
    {
        return $this->hasOne('App\Models\Area','code','province_id');
    }

    public function city()
    {
        return $this->hasOne('App\Models\Area','code','city_id');
    }
    public function district()
    {
        return $this->hasOne('App\Models\Area','code','district_id');
    }
    
    
    /***
     * @param $filter
     * @return bool
     * 同步收货地址表
     */
    public function addOrderAddress($filter)
    {
        $area = new Area();
        $address = (new Address())->getInfo($filter['address_id']);
        $this->order_id = $filter['order_id'];
        $this->name = $address->name;
        $this->phone = $address->phone;
        $this->detail = $address->detail;
        $this->province_id = $address->province_id;
        $this->city_id = $address->city_id;
        $this->district_id = $address->district_id;
        return $this->save();
    }
}
